﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Threading;

namespace CppAddPluginWrapper
{
    public class CppAddWrapperPlugin : Alysa.Plugin
    {
       
        [DllImport(@"CppAdder.dll", EntryPoint = "Add", CallingConvention = CallingConvention.Cdecl)]
        public static extern Int32 Add(Int32 x, Int32 y);


        public CppAddWrapperPlugin() { }

        private static Random x = new Random();

        public override Alysa.PluginExecutionResult execute(Alysa.PluginInputData iInput)
        {
               
            int val = x.Next(1000, 10000);
            for (int i = 0; i < val; i += 20)
            {
                Thread.Sleep(20);
                Thread.Yield();
                if (ShouldStop())
                {
                    throw new Alysa.ExecutionRequestedToStopException();
                }
            }

            Int32 r = Add((Int32)iInput.getX(), (Int32)iInput.getY());
            return new Alysa.PluginExecutionResult(Alysa.PluginExecutionResult.STATUS.SUCCESS, r);          
        }
    }
}
